//
//  HWFenXiangGameView.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/9/9.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWFenXiangGameView.h"

@interface HWFenXiangGameView()
@property(strong,nonatomic) UIView *grayView;
//@property(strong,nonatomic) UIView *whiteView;
@property(strong,nonatomic) UIView *fenxiangView;
@property(strong,nonatomic) NSArray *icoArr;
@property(strong,nonatomic) NSArray *listArr;


@end

@implementation HWFenXiangGameView


- (instancetype)initWithFrame:(CGRect)frame  {
    
    if (self  = [super initWithFrame:frame]) {
        // 添加灰色背景
        [self addgrayView];
        
        [self setupUI];
        
        
    }
    return  self;
    
}

//  设置UI
- (void)setupUI {
    
    self.fenxiangView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenH-138-38-TabbarSafeBottomMargin, kScreenW, 138+38+TabbarSafeBottomMargin)];
    self.fenxiangView.backgroundColor = RGB(240, 244, 246);
    [self addSubview:self.fenxiangView];
    
    
    UILabel *fenxianlabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 16, kScreenW, 13)];
    fenxianlabel.text = @"分享游戏";
    fenxianlabel.font = [UIFont systemFontOfSize:13];
    fenxianlabel.textColor = RGB(51, 51, 51);
    fenxianlabel.textAlignment =  NSTextAlignmentCenter;
    [self.fenxiangView  addSubview:fenxianlabel];
    
    self.listArr = @[@"微信",@"朋友圈",@"QQ",@"QQ空间"];
    self.icoArr = @[@"share_w",@"share_q",@"share_qqico",@"share_c"];
    CGFloat jianju = (kScreenW - 82-4*50)/3;
    // CGFloat  shujianju = (166-100)/3;

    for (int i = 0 ; i < self.listArr.count; i++) {
      

        UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake(jianju*i+41+i*50, 52, 50, 50) Title:self.listArr[i] Image:self.icoArr[i] Font:13 Color:RGB(51, 51, 51) Target:self Selector:@selector(buttonTap:)];
        butt.tag = i;
        [butt layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:10];
        // butt.backgroundColor = [UIColor redColor];
        [self.fenxiangView addSubview:butt];

    }
    
    UIView *fengeview = [[UIView alloc]initWithFrame:CGRectMake(0,137, kScreenW, 1)];
    fengeview.backgroundColor = RGB(215, 215, 215);
    
    
    [self.fenxiangView addSubview:fengeview];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 138, kScreenW, 38);
    [button setTitle:@"取消分享" forState:UIControlStateNormal];
    [button setTitleColor:RGB(51, 51, 51) forState:UIControlStateNormal];
    [button addTarget:self action:@selector(quiabuttontap) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.fenxiangView addSubview:button];
    
    
    
    
    
    
    
    
    
    
}


- (void)relayoutTheChildControls {
//    // self.whiteView.backgroundColor = [UIColor redColor];
//    self.whiteView.frame = CGRectMake(0, self.whibackvieY, kScreenW, 120);
//    self.grayView.frame = CGRectMake(0, self.whibackvieY+120, kScreenW, kScreenH-self.whibackvieY-118+10);
//

    
}






// 添加灰色View
-(void)addgrayView {
    
    self.grayView = [[UIView alloc]init];
    self.grayView.frame  = CGRectMake(0,0, kScreenW, kScreenH);
    
    self.grayView.backgroundColor =  RGB(51, 51, 51);
    self.grayView.alpha = 0.6;
    [self addSubview:self.grayView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
    //  tap.delegate = self;
    [self.grayView addGestureRecognizer:tap];
    
    
    
    
}

- (void)tapView:(UITapGestureRecognizer *)touch {
    
    [touch.view.superview removeFromSuperview];
    //   [[NSNotificationCenter defaultCenter] postNotificationName:@"notifyName1" object:nil];
    
    
}


//点击buton 按钮

- (void)buttonTap:(UIButton *)sender {
    
    [self.delegate xuazhongTag:(int)sender.tag];
    
    
    
   
    
}

#pragma mark ------ 取消
- (void)quiabuttontap {
    
    [self removeFromSuperview];
    
    
}



//-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
//
//    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
//
//        return NO;
//    }else if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableView"]) {
//
//
//        return NO;
//    }
//    return YES;
//
//
//}


@end
